package com.pactera.integral.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.pactera.integral.common.repository.ResultMap;
import com.pactera.integral.common.web.GenericController;
import com.pactera.integral.common.web.Response;
import com.pactera.integral.entity.UserAdditionalScore;
import com.pactera.integral.service.UserAdditonalScoreService;


@CrossOrigin
@RestController
@RequestMapping("wx/userAdditional")
public class UserAdditonalScoreController extends GenericController {

	@Autowired
	private UserAdditonalScoreService userAdditionalScoreService;

	@RequestMapping(value = "/save/{staffId}", method = RequestMethod.POST)
	public Response addScore(@PathVariable("staffId") String staffId,
			@RequestBody UserAdditionalScore userAdditionalScore) {
		return this.normal(userAdditionalScoreService.addScore(staffId, userAdditionalScore));
	}

	/**
	 * 第三方对单人的所有额外分进行一键审核
	 * 
	 * @param list
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/save/all", method = RequestMethod.POST)
	public Response submitAllScore(@RequestBody List<UserAdditionalScore> list) throws Exception {
		return this.normal(userAdditionalScoreService.submitScore(list));
	}

	/**
	 * 第三方对所有人的所有额外分进行一键审核
	 * 
	 * @param list
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/submit/all", method = RequestMethod.GET)
	public Response submitAllScorebyAdmin(@RequestParam String staffId) {
		return this.normal(userAdditionalScoreService.submitAllScorebyAdmin(staffId));
	}

	@RequestMapping(value = "/search/list", method = RequestMethod.GET)
	public Response getAdditionalScoreList(@RequestParam String status, @RequestParam String userId) {
		return this.normal(userAdditionalScoreService.getAdditionalScoreList(status, userId));
	}

	@RequestMapping(value = "/search/detail", method = RequestMethod.GET)
	public Response getAdditionalScoreDetail(@RequestParam String scoreId) {
		return this.normal(userAdditionalScoreService.getAdditionalScoreDetail(scoreId));
	}

	@RequestMapping(value = "/user", method = RequestMethod.GET)
	public Response getUserId(@RequestParam String status, @RequestParam String staffId) {
		List<ResultMap<String, Object>> list = userAdditionalScoreService.getUserId(status, staffId);

		return this.normal(list);
	}

	@RequestMapping(value = "/apply/history", method = RequestMethod.GET)
	public Response getApplyHistory(@RequestParam String staffId, @RequestParam String year,
			@RequestParam String month) {
		List<ResultMap<String, Object>> list = userAdditionalScoreService.getApplyHistory(staffId, year, month);

		return this.normal(list);
	}

	/**
	 * 获取所有额外分项的信息
	 * 
	 * @param scoreType
	 * @return
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public Response getAllScoreList(@RequestParam String scoreType, @RequestParam String category) {
		List<ResultMap<String, Object>> list = userAdditionalScoreService.getAllScoreList(scoreType, category);

		return this.normal(list);
	}

}
